package com.demo.thread.semaphore;

/**
 * @author : YU.TAN
 * @date : 2021/11/8 10:51
 *  计数型信号量
 */
public class CountingSemaphore {
    private int signals = 0;
    public synchronized void take() {
        this.signals++;
        this.notify();
    }
    public synchronized void release() throws InterruptedException {
        while (this.signals == 0){
            wait();
        }
        this.signals--;
    }
}
